home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asmmacro.zip / MACROS.ASM
Assembly Source File  |  1992-01-12  |  9KB  |  284 lines

  1. ;^^^^^^^^^^^^^^^^^^^^^^^8086 Assembler MACROS^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2. ;       By Mark Stout, Compaq Computer
  3. ;==============================================================================
  4. ;
  5. ;       DISPLAY Macro:
  6. ;
  7. ;       Displays string of characters on standard output.  String must be
  8. ;       terminated by '$'.
  9. ;
  10. ;       Format:
  11. ;
  12. ;               DISPLAY message
  13. ;
  14. ;       where message is the offset of the string.
  15. ;
  16. ;==============================================================================
  17.  
  18. DISPLAY   MACRO    MESSAGE
  19.  
  20.         PUSH    DX
  21.         PUSH    AX
  22.  
  23.         LEA     DX, MESSAGE             ;Point to offset of string
  24.         MOV     AH, 9H                  ;Use DOS function 9H
  25.         INT     21H
  26.  
  27.         POP     AX
  28.         POP     DX
  29.  
  30. ENDM
  31.  
  32. ;==============================================================================
  33. ;
  34. ;       INPUT Macro:
  35. ;
  36. ;       Reads string of characters from standard input.
  37. ;
  38. ;       Format:
  39. ;
  40. ;       INPUT buffer
  41. ;
  42. ;       where buffer is the offset of an input buffer with this format:
  43. ;
  44. ;               First byte:  Maximum number of characters desired, including
  45. ;                            terminating CR.
  46. ;
  47. ;               Second Byte: Storage for actual number of characters read,
  48. ;                            returned by macro.
  49. ;
  50. ;               Third Byte:  Start of buffer for characters read.
  51. ;
  52. ;==============================================================================
  53.  
  54. INPUT   MACRO   BUFFER
  55.  
  56.         PUSH    AX
  57.         PUSH    DX
  58.  
  59.         LEA     DX, BUFFER              ;Point to start of input buffer
  60.         MOV     AH, 0AH                 ;Use DOS function Ah
  61.         INT     21H
  62.  
  63.         POP     DX
  64.         POP     AX
  65.  
  66. ENDM
  67.  
  68. ;==============================================================================
  69. ;
  70. ;       BIN2ASCII Macro:
  71. ;
  72. ;       Converts binary value in DX to ASCII string.
  73. ;
  74. ;       Format:
  75. ;
  76. ;               BIN2ASCII length, out_buffer
  77. ;
  78. ;       where length is the # of characters for the output string, including
  79. ;       leading spaces, and out_buffer is location of output buffer.
  80. ;
  81. ;==============================================================================
  82.  
  83. BIN2ASCII  MACRO  LENGTH, OUT_BUFFER
  84.         LOCAL   ASCIILOOP, BLANK, NEXT, PAD  ;Define local labels for multiple invocations
  85.  
  86.         PUSH    AX
  87.         PUSH    BX
  88.         PUSH    CX
  89.         PUSH    DX
  90.         PUSH    DI
  91.  
  92.         MOV     CX, LENGTH              ;Set up CX as counter of ASCII digits
  93.         MOV     AX, DX                  ;Move binary value to accumulator
  94.         MOV     BX, 10                  ;Set up BX as decimal base
  95.  
  96. ASCIILOOP:
  97.         MOV     DI, CX                  ;Use DI for index relative addressing of ASCII string
  98.         CMP     AX, 0                   ;If accumulator = 0, pad left of string with blanks
  99.         JE      BLANK
  100.         MOV     DX, 0                   ;Prepare DX as high word of dividend
  101.         DIV     BX                      ;Divide remaining value by decimal base
  102.         ADD     DX, 30H                 ;Convert remainder to ASCII for use in string
  103.         MOV     [OUT_BUFFER+DI-1], DL   ;Converted remainder is next least significant digit in string
  104.         JMP     NEXT
  105.  
  106. BLANK:  CMP     CX, LENGTH              ;Checks for binary value = 0
  107.         JNE     PAD
  108.         MOV     [OUT_BUFFER+DI-1], '0'
  109.         JMP     NEXT
  110.  
  111. PAD:    MOV     [OUT_BUFFER+DI-1], ' '  ;Pads left of string with blanks when necessary
  112. NEXT:   LOOP    ASCIILOOP               ;Calculate next digit of string
  113.  
  114.         POP     DI
  115.         POP     DX
  116.         POP     CX
  117.         POP     BX
  118.         POP     AX
  119.  
  120. ENDM
  121.  
  122. ;==============================================================================
  123. ;
  124. ;       PRINT Macro:
  125. ;
  126. ;       Prints ASCII string of characters, terminated by '$'.
  127. ;
  128. ;       Format:
  129. ;
  130. ;               PRINT   print_output
  131. ;
  132. ;       where print_output is the offset of the string.
  133. ;
  134. ;==============================================================================
  135.  
  136. PRINT   MACRO   PRT_OUTPUT
  137.         LOCAL PRINT_DIGIT, END_O_STRING ;Define local labels for multiple invocation
  138.  
  139.         PUSH    DX
  140.         PUSH    SI
  141.         PUSH    AX
  142.  
  143.         MOV     SI, 1                   ;Initialize SI for memory addressing of characters to be printed
  144.         MOV     AH, 5                   ;Ready AH for DOS Function Call #5
  145.  
  146. PRINT_DIGIT:
  147.         MOV     DL, [PRT_OUTPUT+SI-1]   ;Load character from string into DL
  148.         CMP     DL, '$'                 ;If character = $, terminate print
  149.         JE      END_O_STRING
  150.         INT     21H                     ;DOS Function Call #5
  151.         INC     SI                      ;Ready index for next character
  152.         JMP     PRINT_DIGIT
  153.  
  154. END_O_STRING:
  155.         POP     AX
  156.         POP     SI
  157.         POP     DX
  158.  
  159. ENDM
  160.  
  161. ;==============================================================================
  162. ;
  163. ;       ASCII2BIN Macro:
  164. ;
  165. ;       Converts a decimal, ASCII string to a binary value.  Works for numbers
  166. ;       less than 65,535.  Inputs over this range cause invalid results,
  167. ;       indicated by AX = FFFFh after invocation.
  168. ;
  169. ;       Format:
  170. ;
  171. ;               ASCII2BIN ascii_string
  172. ;
  173. ;       where ascii_string is the offset of the ASCII string.
  174. ;
  175. ;       Input:  AX = Number of ASCII digits in string.
  176. ;
  177. ;       Output: AX = Binary value of number.
  178. ;
  179. ;==============================================================================
  180.  
  181. ASCII2BIN   MACRO  ASCII_STRING
  182.         LOCAL   DIGIT_LOOP, OKAY
  183.  
  184.         PUSH    CX
  185.         PUSH    DX
  186.         PUSH    BX
  187.         PUSH    SI
  188.  
  189.         MOV     CX, AX                  ;Set up conversion loop counter
  190.         MOV     SI, 0                   ;Initialize digit index
  191.         MOV     AX, 0                   ;Initialize sum at 0
  192.         MOV     BX, 10                  ;Use BX as decimal base
  193.  
  194. DIGIT_LOOP:
  195.         MUL     BX                      ;Multiply accumulator by decimal base
  196.         ADD     AL, ASCII_STRING[SI]    ;Add next digit from ASCII string
  197.         ADC     AH, 0                   ;Complete addition through high byte of AX
  198.         SUB     AX, 30H                 ;Convert ASCII addition to binary value
  199.         INC     SI                      ;Increment ASCII digit index
  200.         LOOP    DIGIT_LOOP              ;Repeat for next digit
  201.  
  202.         CMP     DX, 0                   ;If DX not = 0, result will be invalid
  203.         JE      OKAY
  204.         MOV     AX, 0FFFFH              ;Flag invalid results
  205.  
  206. OKAY:
  207.         POP     SI
  208.         POP     BX
  209.         POP     DX
  210.         POP     CX
  211.  
  212. ENDM
  213.  
  214. ;===============================================================================
  215. ;
  216. ;       SCROLL_UP Macro:
  217. ;
  218. ;       Uses BIOS function INT 10h, Subfunction 6, to scroll a pre-defined
  219. ;       window a given number of lines. New lines are white foreground on
  220. ;       black background.
  221. ;
  222. ;       Format:
  223. ;
  224. ;       SCROLL_UP  lines, TL_row, TL_col, BR_row, BR_col
  225. ;
  226. ;       where:  lines  = # of lines to scroll (0 for entire window)
  227. ;               TL_row = row of top, left corner
  228. ;               TL_col = column of top, left corner
  229. ;               BR_row = row of bottom, right corner
  230. ;               BR_col = column of bottom, right corner
  231. ;
  232. ;===============================================================================
  233.  
  234. SCROLL_UP       MACRO   LINES, TL_ROW, TL_COL, BR_ROW, BR_COL
  235.  
  236.         PUSH    AX
  237.         PUSH    BX
  238.         PUSH    CX
  239.         PUSH    DX
  240.  
  241.         MOV     AH, 6
  242.         MOV     AL, LINES
  243.         MOV     CH, TL_ROW
  244.         MOV     CL, TL_COL
  245.         MOV     DH, BR_ROW
  246.         MOV     DL, BR_COL
  247.         MOV     BH, 7
  248.  
  249.         INT     10H
  250.  
  251.         POP     DX
  252.         POP     CX
  253.         POP     BX
  254.         POP     AX
  255.  
  256. ENDM
  257.  
  258. ;===============================================================================
  259. ;
  260. ;       LOCATE Macro:
  261. ;
  262. ;       Uses BIOS function INT 10h, Subfunction 2, to position cursor.
  263. ;
  264. ;       Input:  DH = Row coordinate (0-24)
  265. ;               DL = Column coordinate (